﻿namespace LaoLuo
{
    /// <summary>
    /// 
    /// </summary>
    public static class ResultExtensions
    {
        #region extensions

        /// <summary>
        /// set status to <see cref="ResultBase.ResultStatus.失败"/> with specified message
        /// </summary>
        /// <param name="result"></param>
        /// <param name="format"></param>
        /// <param name="args"></param>
        public static void Fail(this Result result, string format, params object[] args)
        {
            result.Message = string.Format(format, args);
            result.Status = ResultBase.ResultStatus.失败;
        }

        /// <summary>
        /// set status to <see cref="Result.ResultStatus.成功"/> with specified data
        /// </summary>
        /// <param name="result"> </param>
        /// <param name="data"></param>
        public static void Succeed(this Result result, object data)
        {
            result.Data = data;
            result.Status = ResultBase.ResultStatus.成功;
        }

        /// <summary>
        /// set status to <see cref="ResultBase.ResultStatus.失败"/> with specified message
        /// </summary>
        /// <param name="result"> </param>
        /// <param name="format"></param>
        /// <param name="args"></param>
        public static void Fail<T>(this Result<T> result, string format, params object[] args)
        {
            result.Message = string.Format(format, args);
            result.Status = ResultBase.ResultStatus.失败;
        }

        /// <summary>
        /// set status to <see cref="Result.ResultStatus.成功"/> with specified data
        /// </summary>
        /// <param name="result"> </param>
        /// <param name="data"></param>
        public static void Succeed<T>(this Result<T> result, T data)
        {
            result.Data = data;
            result.Status = ResultBase.ResultStatus.成功;
        }

        #endregion
    }
}
